<template>
  <div>
    <van-nav-bar title="草稿箱" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div v-if="searchList.length===0" class="van_card">
      <van-empty image="search" description="没有数据" />
    </div>
    <div class="van_card approvel_item" v-for="(item, j) in searchList" :key="j">
      <p>旅客：{{ item.HCPName }}</p>
      <p>UCI CODE：{{ item.UCICode }}</p>
      <div class="approvel_item_btn">
        <van-button type="info" size="mini" @click="edit_d(item)">编辑</van-button>
        <van-button type="danger" size="mini" @click="sketchDelect(item)">删除</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import apilist from "../utils/apiList";
export default {
  data() {
    return {
      searchList: [],
      eventId: "",
    };
  },
  created() {
    let eventid = JSON.parse(sessionStorage.getItem("eventid"));
    this.eventId = eventid;
    console.log(this.eventId);
    let accountname = JSON.parse(sessionStorage.getItem("accountname"));
    this.accountname = accountname.cName;
    this.$axios
      .get(apilist[0] + "/GetDraftAttendeeListByEventid?eventid=" + eventid)
      .then((res) => {
        this.searchList = res.data.filter(function (v, i) {
          return v.SignedID != "D";
        });
      });
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    // 编辑功能
    edit_d: function (item) {
      sessionStorage.setItem("editlc_nhcp", JSON.stringify(item));
      window.location.href =
        "https://ezway.efasco.com/roche_meeting/dist/newhcp.html?eventId=" +
        this.eventId +
        "&acc0=" +
        this.accountname +
        "&id=" +
        item.$id+"&originpath="+window.location.origin+window.location.pathname;
      // router.push('/a/listcollect/lc_nhcp/lc_nhcp');
    },
    // 删除当前人的草稿
    sketchDelect(item) {
      this.$dialog
        .confirm({
          title: "提示",
          message: "是否删除当前草稿",
        })
        .then(() => {
          this.$axios
            .get(apilist[0] + "/DeleteAttendee?attendeeid=" + item.AttendeeID)
            .then((e) => {
              if (e.data != "success") {
                this.$notify({
                  type: "danger",
                  message: "删除失败",
                  duration: 1000,
                });
                return;
              }
              // that.$router.go(0);
              window.location.reload();
              // this.searchList.map((v, i) => {
              //   if (v.$id === item.$id) {
              //     this.searchList.splice(i, 1);
              //     this.$forceUpdate()
              //   }
              // });
            });

          // on confirm
        })
        .catch(() => {
          // on cancel
        });
    },
    // 去报名页面编辑
  },
};
</script>

<style scoped>
.approvel_item_btn{
  top: 15px;
}
</style>